﻿using Inovout.Data.Domain;
using Inovout.Web.Mvc;
using KuaJing.Orders.Domain;
using KuaJing.Orders.Service;
using System.Linq;
using System.Web.Mvc;

namespace KuaJing.Tasks.WebPages.Controllers
{
    public class CustomerController : RepositoryController<Customer>
    {
        public override ActionResult Index(QueryCriteria queryCriteria)
        {
            queryCriteria = QueryCriteriaBuilder.FilterFor(f => f.Name, FilterOperation.Like)
              .FilterFor(t => t.SigningDate, FilterOperation.GtEq)
              .FilterFor(t => t.SigningDate, FilterOperation.LeEq)
              .FilterFor(t => t.Butler.Person.Name, FilterOperation.Like)
              .FilterFor(t => t.Sales.Person.Name, FilterOperation.Like)
              .FilterFor(t => t.Source, FilterOperation.Eq)
              .OrderDescendingFor(t => t.CreatedTime)
              .Merge(queryCriteria).QueryCriteria;
            return View(Query(queryCriteria));
        }

        [HttpPost]
        public ActionResult Upload()
        {
            StoreFile(f => ExecuteServiceAsync<CustomerService>(service => service.Import(f)));
            return View(true);
        }

    }
}